﻿using System.Net;

namespace GSOrganization.Application
{
    /// <summary>
    /// WEBAPI通用返回泛型基类
    /// </summary>
    public class ResponseModel
    {
        /// <summary>
        /// 操作消息【当Status不为 200时，显示详细的错误信息】
        /// </summary>
        public string msg { get; set; }
         
        /// <summary>
        /// 操作状态码，200为正常
        /// </summary>
        public HttpStatusCode code { get; set; }

         
        public ResponseModel()
        {
            code = HttpStatusCode.OK;
          
            msg = "操作成功";
        }
        public static ResponseModel SucceedDelete()
        {
            ResponseModel res = new ResponseModel();          
            res.msg = "删除成功";
            return res;

        }
        public static ResponseModel Succeed()
        {
            ResponseModel<string> res = new ResponseModel<string>();
            res.data = "ok";
            return res;

        }
        public static ResponseModel Succeed(object data)
        {
            ResponseModel<object> res = new ResponseModel<object>();
            res.data=data;
            return res;

        }
        public static ResponseModel Fail(string message, System.Net.HttpStatusCode code= System.Net.HttpStatusCode.BadRequest)
        {
            ResponseModel res = new ResponseModel();
            res.code = code;
            res.msg = message;
            return res;

        }
    }



    /// <typeparam name="T"></typeparam>
    public class ResponseModel<T> : ResponseModel
    {
        /// <summary>
        /// 总条数；只有当分页的时候才会用到
        /// </summary>
        public int count { get; set; }
        /// <summary>
        /// 操作结果
        /// </summary>
        public T data { get; set; }
    }
}